<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/12/8
 * Time: 12:05
 */
require('../vendor/autoload.php');
require('../define.php');
require('util/WechatPlatform.php');

$app = \wechat\util\WechatPlatform::getOfficiaInstance();
if ($_SERVER['REQUEST_METHOD'] == 'GET' && !empty($_GET["signature"]) && !empty($_GET["timestamp"]) && !empty($_GET["nonce"])) {
    $response = $app->server->serve();
    // 将响应输出
    $response->send();
    exit; // Laravel 里请使用：return $response;
} else {
    $app->server->push(function ($message) {
        switch ($message['MsgType']) {
            case 'event':
                return '收到事件消息';
                break;
            case 'text':
                return '收到文字消息';
                break;
            case 'image':
                return '收到图片消息';
                break;
            case 'voice':
                return '收到语音消息';
                break;
            case 'video':
                return '收到视频消息';
                break;
            case 'location':
                return '收到坐标消息';
                break;
            case 'link':
                return '收到链接消息';
                break;
            case 'file':
                return '收到文件消息';
                break;
            default:
                return '收到其它消息';
                break;
        }
    });
    $response = $app->server->serve();
    $response->send();
    exit; // Laravel 里请使用：return $response;
}

